<template>
  <!-- 报项中心 -->
  <div v-loading="loading" class="gl_pb_20">
    <div class="gl_my_15">
      <el-input v-model="Api_GET_EventsManagementRegisterCompetitionListQO.Filter" style="width:20%" suffix-icon="el-icon-search" clearable placeholder="搜索" size="mini" @change="getMessageList()" />
    </div>
    <div v-if="messageList.length > 0">
      <el-table size="mini" class="notice_table" :data="messageList">
        <el-table-column type="index" label="序号" width="50" />
        <el-table-column prop="name" label="赛事名称">
          <template slot-scope="{row}">
            <span class="title" @click="changeRoute(row)">{{ row.parent && row.parent.name ? row.parent.name + ' - ' : '' }}{{ row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="比赛开始时间" width="180">
          <template slot-scope="{row}">
            <span>{{ row.startTime | FormatDate('yyyy-MM-dd') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="{row}">
            <el-button type="text" @click="detail(row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div v-else class="gl_noData">
      <p>暂无数据</p>
    </div>
    <el-row class="gl_pt_20" style="text-align: center;">
      <el-pagination
        :current-page="Api_GET_EventsManagementRegisterCompetitionListQO.Page"
        :page-size="Api_GET_EventsManagementRegisterCompetitionListQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>
<script>
import { api_GET_EventsManagementRegisterCompetitionList } from '@/extend/api/gameswaggerApi/app.js';
import { Api_GET_EventsManagementRegisterCompetitionListQO } from '@/lib/form/game/swaggerForm';
import { mapState } from 'vuex';

export default {
  name: 'SignUp',
  data() {
    return {
      Api_GET_EventsManagementRegisterCompetitionListQO: new Api_GET_EventsManagementRegisterCompetitionListQO(),
      loading: false,
      totalPage: 0,
      messageList: []
    };
  },
  computed: {
    ...mapState({
      currentUserType: state => state.user.currentUserType
    })
  },
  watch: {
    // 'currentUserType': {
    //   handler: function(val) {
    //     if (!val) return;
    //     this.getMessageList();
    //   },
    //   immediate: true
    // }
  },
  created() {
    if (this.currentUserType) {
      this.getMessageList();
    }
  },
  methods: {
    // 获取报项中心列表
    getMessageList(page) {
      if (!(this.currentUserType && (this.currentUserType.delegationId || this.currentUserType.registerId))) return;
      this.loading = true;
      this.Api_GET_EventsManagementRegisterCompetitionListQO.DelegationId = this.currentUserType.delegationId;
      this.Api_GET_EventsManagementRegisterCompetitionListQO.RegisterId = this.currentUserType.registerId;
      this.Api_GET_EventsManagementRegisterCompetitionListQO.IncludeParent = true;
      this.Api_GET_EventsManagementRegisterCompetitionListQO.Sorting = 'startTime desc';
      this.Api_GET_EventsManagementRegisterCompetitionListQO.Page = page || 1;
      this.Api_GET_EventsManagementRegisterCompetitionListQO.SkipCount = (this.Api_GET_EventsManagementRegisterCompetitionListQO.Page - 1) * this.Api_GET_EventsManagementRegisterCompetitionListQO.MaxResultCount;
      api_GET_EventsManagementRegisterCompetitionList(this.Api_GET_EventsManagementRegisterCompetitionListQO).then(res => {
        this.messageList = res.items;
        this.totalPage = res.totalCount;
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });
    },
    // 点击赛事标题进行路由跳转
    changeRoute(gameInfo) {
      var a = document.createElement('a');
      var event = new MouseEvent('click');
      a.href = `${location.origin}/game.html#/home/${gameInfo.route }/info`;
      a.target = '_blank';
      a.dispatchEvent(event);
    },
    // 查看详情
    detail(row) {
      const { query } = this.$route;
      query.id = row.id;
      this.$router.push({
        path: '/myCenter/signUp/gameSignUp/detail',
        query: query
      });
    },
    // 分页
    sizeChange(MaxResultCount) {
      this.Api_GET_EventsManagementRegisterCompetitionListQO.MaxResultCount = MaxResultCount;
      this.getMessageList();
    },
    pageIndexChange(currentPage) {
      this.getMessageList(currentPage);
    }
  }
};
</script>
<style scoped>
.el-table {
  border: none;
}
.el-table::before {
  background-color: #ffffff;
}
.el-table /deep/ th{
  border-right: none;
  background: #ffffff;
}
.el-table /deep/ thead th{
  background: #ffffff;
}
.el-table /deep/ td {
  border-right: none;
  font-size: 14px;
}
.title {
  cursor: pointer;
}
.title:hover{
  color: #1890ff;
  text-decoration: underline;
}
.notice_table {
  border-top: 1px solid #dfe6ec;
  border-right: none !important;
}
</style>
